/**
 * 搜索字符串，返回给定字符串的坐标，若无则返回-1
 */

#include <stdio.h>

#define MAXLINE 1000

int mgetline(char s[], int n);
int strindex(char s[], char t[]);

int main() {
    char pattern[] = "ello";
    char line[MAXLINE];
    int found = 0;
    while (mgetline(line, MAXLINE) > 0) {
        if (strindex(line, pattern) >= 0) {
            found++;
            printf("%s", line);
        }
    }

    return found;
}

int mgetline(char s[], int n) {
    int i, c;
    i = 0;
    while (--n > 0 && (c = getchar()) != EOF && c != '\n') {
        s[i++] = c;
    }
    if (c == '\n')
        s[i++] = '\n';
    s[i] = '\0';

    return i;
}

int strindex(char s[], char t[]) {
    int i, j, k;
    for (i = 0; s[i] != '\0'; i++) {
        for (j = i, k = 0; t[k] != '\0' && s[j] == t[k]; j++, k++) ;
        if (k > 0 && t[k] == '\0')
            return i;
    }
    return -1;
}
